import { getSecondGoodsTypeDataByIdData } from "@/apis/goodsType";
import { useRoute, onBeforeRouteUpdate } from "vue-router";
import { onMounted, ref } from "vue"


export function useSecondGoodsTypeData() {
    const route = useRoute();
const goodsSecondTypeData = ref(Object);
const getSecondGoodsTypeDataById = async (id = route.params.id) => {
  const res = await getSecondGoodsTypeDataByIdData(id);
  goodsSecondTypeData.value = res.data;
};
onBeforeRouteUpdate((to) => {
  // 存在问题：使用最新的路由参数请求最新的分类数据
  getSecondGoodsTypeDataById(to.params.id);
});
onMounted(() => {
  getSecondGoodsTypeDataById();
});
    return {
        goodsSecondTypeData
    }
}